{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "['data_batch_1', 'data_batch_2', 'data_batch_5', 'data_batch_4', 'data_batch_3', 'batches.meta', 'readme.html', 'test_batch']\n"
     ]
    }
   ],
   "source": [
    "import pickle\n",
    "import numpy as np\n",
    "import os\n",
    "\n",
    "CIFAR_DIR = \"/home/herb/code/data/dataset/cf10data\"\n",
    "\n",
    "print(os.listdir(CIFAR_DIR))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "dict_keys([b'batch_label', b'labels', b'data', b'filenames'])\n"
     ]
    }
   ],
   "source": [
    "with open(os.path.join(CIFAR_DIR, \"data_batch_1\"),'rb') as f:\n",
    "    data1 = pickle.load(f,encoding='bytes')\n",
    "    print (data1.keys())\n",
    "    "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<matplotlib.image.AxesImage at 0x7fe4c1c83518>"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAPsAAAD5CAYAAADhukOtAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4xLjIsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy8li6FKAAAaCElEQVR4nO2da4ycZ3XH/2dmZ3ft3U28u44ds74ljksJARK6tUAgREGgFCEFCo3ChygfIowqIhWJqopSqaRSP0BVQHyoqEwTEaqUEBIuUZW2pBEi8MVkYxzHiQNxjEN8iZ34wq5vOzszpx/mtbRJ3/Of2Xd2Zkye/0+yPPuced73zDPvmcvzn3OOuTuEEG9+Sv12QAjRGxTsQiS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ZrA68AAAAABJRU5ErkJggg==\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "# 拿到第100张图片，\n",
    "image_arr = data1[b'data'][100]\n",
    "# 解析三通道\n",
    "image_arr = image_arr.reshape((3,32,32))\n",
    "# 转换RGB\n",
    "image_arr = image_arr.transpose((1,2,0))\n",
    "import matplotlib.pyplot as plt\n",
    "%matplotlib inline\n",
    "plt.imshow(image_arr)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.8"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
